<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <title>{:config('web_site_title')}后台管理系统！</title>
    <link rel="shortcut icon" href="__PUBLIC__/img/favicon.ico">
    <link href="__PUBLIC__/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/css/font-awesome.min.css" rel="stylesheet">
    <link href="__PUBLIC__/css/animate.min.css" rel="stylesheet">
    <link href="__PUBLIC__/css/style.min.css?v=4.1.0" rel="stylesheet">
	<link rel="stylesheet" href="__STATIC__/css/xadmin.css?time=1">

    {block name='css'}{/block}

    <script type="text/javascript" src="__PUBLIC__/js/jquery.min.js?v=2.1.4"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js?v=3.3.6"></script>
    <script type="text/javascript" src="__PUBLIC__/js/plugins/layer/layer.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/common.js"></script>

    <script src="__PUBLIC__/js/plugins/layer/extend/layer.ext.js"></script>
</head>

{block name='body'}{/block}

<script>
    function showMyLoading() {
        var loading = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        var sto = setTimeout(function(){
            layer.msg('服务器繁忙，请耐心等待。。。');
            sto = setTimeout(function(){
                layer.close(loading);
            }, 15000);
        }, 15000);
        return {loading:loading,sto:sto};
    }
    function hideMyLoading(obj) {
        layer.close(obj.loading);
        clearTimeout(obj.sto);
    }

    function myRequestRefresh(self, url, params) {
        $(self).addClass('ed');
        var obj = showMyLoading();
        $.post(url, params, function(data){
            hideMyLoading(obj);
            layer.msg(data.info);
            if (data.status == 'y') {
                setTimeout(function(){window.location.reload();},1500);
            } else {
                $(self).removeClass('ed');
            }
        }, 'json');
    }

    function del(id){
        if ($('body').hasClass('ed')) {
            return false;
        }

        layer.confirm('真的要删除吗？删除后将无法找回！', {
            btn: ['确定','取消'] //按钮
        }, function(){
            myRequestRefresh('body', "{:url('del')}", {id:id});
        }, function(){

        });
    }


    /**
     * 多图ajax图片上传函数
     */
    function ajaxImgFileAll(obj){
        var ul = $(obj).parent();
        var file = $(obj).find('input') ;
        var inputname = $(obj).attr('data-inputname') ;
        var maxlength = $(obj).attr('max-imglength') ;
        var img = $(obj).find('.imgs') ;
        var loading = $(obj).find('.img-loading') ;
        file.unbind('change').on("change",function(event) {
            file.hide();
            img.hide();
            loading.show();

            var files = event.target.files || event.dataTransfer.files;
            var length = ul.find('input[type="hidden"]').length ;
            console.log(length);
            var timestamp = Date.parse(new Date());
            for(var i = 0 ; i < files.length ; i ++ ) {
                if (length + i < maxlength) {
                    uploadRunxue(files[i],obj,inputname , timestamp ++)
                }
                if( length +i+1 == maxlength){
                    $(obj).hide() ;
                    break ;
                }
            }
            img.show();
            loading.hide();
            file.show();
        });
    }
    function uploadRunxue(file,obj,inputname,timestamp){
        var html = '<li class="input'+timestamp+'">';
        html += '<img src="__I__/loading.gif"  style="display:block;" class="img-loading"/>';
        html += '<span onclick="delImg(this);">&times;</span>';
        html += '<input type="hidden" name="'+inputname+'" value="">';
        html += '</li>';
        $(obj).before(html);

        var formData = new FormData();
        formData.append('imgFile', file);
        var ajax = new XMLHttpRequest();
        ajax.open("POST", "{:url('Index/saveImg')}", true);
        ajax.send(formData);
        ajax.onreadystatechange = function() {
            if (ajax.readyState == 4) {
                if (ajax.status >= 200 && ajax.status < 300 || ajax.status == 304) {
                    var data = JSON.parse(ajax.responseText);
                    if (data.status == 'y') {

                        $('.input' + timestamp).find('img').remove();
                        $('.input' + timestamp).prepend('<img src="'+data.data.img+'" class="imgs"/>') ;
                        $('.input' + timestamp).find('input').attr('value' ,data.data.img );

                    } else {
                        $('.input' + timestamp).find('span').click();
                    }
                }
            }
        }
    }
    //删除图片
    function delImg(obj){
        var ul = $(obj).parent().parent();
        var a = ul.find('li:last').attr('max-imglength');
        $(obj).parent().remove();
        if( ul.find('input[type="hidden"]').length < a) {
            ul.find('li:last').show();
        }

    }
</script>

{block name='js'}
<script type="text/javascript" src="__PUBLIC__/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/hplus.min.js?v=4.1.0"></script>
<script type="text/javascript" src="__PUBLIC__/js/contabs.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/plugins/pace/pace.min.js"></script>
<script src="__PUBLIC__/js/plugins/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/plugins/validate/messages_zh.min.js"></script>
{/block}
</html>